package com.yike.user.controller;

import com.yike.user.entity.SysSetting;
import com.yike.user.service.SysSettingService;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.SysSettingPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.api.IdParam;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 系统属性配置表 控制器
 *
 * @author Sakura
 * @since 2024-09-29
 */
@Slf4j
@RestController
@RequestMapping("/sysSetting")
@Module("user")
@Api(value = "系统属性配置表API", tags = {"系统属性配置表"})
@ApiIgnore
public class SysSettingController extends BaseController {

    @Autowired
    private SysSettingService sysSettingService;

    /**
     * 添加系统属性配置表
     */
    @PostMapping("/add")
    @OperationLog(name = "添加系统属性配置表", type = OperationLogType.ADD)
    @ApiOperation(value = "添加系统属性配置表", response = ApiResult.class)
    public ApiResult<Boolean> addSysSetting(@Validated(Add.class) @RequestBody SysSetting sysSetting) throws Exception {
        boolean flag = sysSettingService.saveSysSetting(sysSetting);
        return ApiResult.result(flag);
    }

    /**
     * 修改系统属性配置表
     */
    @PostMapping("/update")
    @OperationLog(name = "修改系统属性配置表", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改系统属性配置表", response = ApiResult.class)
    public ApiResult<Boolean> updateSysSetting(@Validated(Update.class) @RequestBody SysSetting sysSetting) throws Exception {
        boolean flag = sysSettingService.updateSysSetting(sysSetting);
        return ApiResult.result(flag);
    }

    /**
     * 删除系统属性配置表
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除系统属性配置表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除系统属性配置表", response = ApiResult.class)
    public ApiResult<Boolean> deleteSysSetting(@PathVariable("id") Long id) throws Exception {
        boolean flag = sysSettingService.deleteSysSetting(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取系统属性配置表详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "系统属性配置表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "系统属性配置表详情", response = SysSetting.class)
    public ApiResult<SysSetting> getSysSetting(@PathVariable("id") Long id) throws Exception {
        SysSetting sysSetting = sysSettingService.getById(id);
        return ApiResult.ok(sysSetting);
    }

    /**
     * 系统属性配置表分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "系统属性配置表分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "系统属性配置表分页列表", response = SysSetting.class)
    public ApiResult<Paging<SysSetting>> getSysSettingPageList(@Validated @RequestBody SysSettingPageParam sysSettingPageParam) throws Exception {
        Paging<SysSetting> paging = sysSettingService.getSysSettingPageList(sysSettingPageParam);
        return ApiResult.ok(paging);
    }

}

